package com.mechat.ui.chats.item

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.custom.base.mvp.MVPBaseFragment
import com.gyf.immersionbar.ImmersionBar
import com.mechat.R
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.sunday.eventbus.SDBaseEvent
import com.yanzhenjie.recyclerview.SwipeRecyclerView
import io.rong.imkit.event.EnumEventTag
import kotlinx.android.synthetic.main.frag_item.*

/**
 * 作者：
 * 时间：2022-03-04
 */
class ItemFragment : MVPBaseFragment<ItemContract.View, ItemPresenter>(), ItemContract.View {
    override val listView: SwipeRecyclerView
        get() = frag_item_list_view
    override val emptyContainer: LinearLayout
        get() = empty_container
    override val chatsRefreshLayout: SmartRefreshLayout
        get() = chats_refresh_layout

    override fun bindLayout(): Int {
        return R.layout.frag_item
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.getString("modelUserCode")?.let { mPresenter?.getDataSize(it) }
    }



    override fun onEventMainThread(event: SDBaseEvent) {
        when (EnumEventTag.valueOf(event.tagInt)) {
            EnumEventTag.MODEL_LIST_REFRESH->{
                mPresenter?.refreshItem(event.data.toString())
            }
            EnumEventTag.MODEL_LIST_ONLINE_REFRESH->{
                mPresenter?.refreshItemOnline(event.data.toString())
            }

            EnumEventTag.MODEL_LIST_REMOVE_UNREAD_REFRESH->{
                mPresenter?.refreshItemUnread(event.data.toString())
            }
            else -> {}
        }
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (!hidden){
            ImmersionBar.with(this)
                .statusBarColor("#4699FF")
                .statusBarDarkFont(false)
                .init()
        }
    }

}